#include <iostream>
#include <thread>
#include <chrono>

#include "server.h"
#include "data.h"

//void smain(RShareMemArray &arr) {
void smain(char *name) {
    RShareMemArray<data_t, 100> *arr = new RShareMemArray<data_t, 100>(name);
    std::cout << "[ S ] name: " << arr->Name() << std::endl;


    for (int i = 11; i <= 20; i++) {
        data_t d = { .a = i, .b = i * i, .c = i * 0.01 };
        int32_t idx = arr->Add(&d);
        std::cout << "[ S ] Added: " << i << ", index: " << idx << ", arr.Length(): " << arr->Length() << std::endl;
        std::this_thread::sleep_for (std::chrono::milliseconds(300));
    }

    std::this_thread::sleep_for (std::chrono::seconds(1));


    arr->Unlink();
    delete arr;

    std::cout << "[ S ] Exit." << std::endl;
}
